package com.android.camera.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import com.android.camera.R;
import android.graphics.drawable.Drawable;

public class ArrowLineView extends View {
    private static final String TAG = "ArrowLineView";

    private Paint mPaint;

    private float startX = 0, startY = 0;
    private float endX = 0, endY = 0;

    private int arrowLength = 20;

    private int width = 0;
    private int height = 0;

    private Drawable mArrowDrawable;
    private int mArrowDrawableWidth;
    private int mArrowDrawableHeight;

    public ArrowLineView(Context context) {
        this(context, null);
    }

    public ArrowLineView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ArrowLineView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        /*
         * mPaint = new Paint(); mPaint.setAntiAlias(true);
         * mPaint.setColor(Color.GREEN); mPaint.setStyle(Paint.Style.STROKE);
         * mPaint.setStrokeWidth(3); PathEffect effect = new DashPathEffect(new
         * float[] { 15, 10, 15, 10 }, 1); mPaint.setPathEffect(effect);
         */

        mArrowDrawable = context.getResources().getDrawable(R.drawable.rgk_arrow_in_middle);
        mArrowDrawableWidth = mArrowDrawable.getIntrinsicWidth();
        mArrowDrawableHeight = mArrowDrawable.getIntrinsicHeight();
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.d(TAG, "ArrowLineView left=" + getLeft() + ", right=" + getRight() + ", top="
                + getTop() + ", bottom=" + getBottom());
        /*
         * startX = width / 2.0f - 54; endX = startX + 108; startY = endY =
         * height / 2.0f; mPaint.setColor(0xFFFFFFFF); Path p = new Path();
         * p.moveTo(startX, startY); p.lineTo(endX, endY); canvas.drawPath(p,
         * mPaint); float delta = (float)Math.sqrt(arrowLength * arrowLength /
         * 2); float x1 = endX - delta; float y1 = endY - delta; float x2 = endX
         * - delta; float y2 = endY + delta; canvas.drawLine(x1, y1, endX, endY,
         * mPaint); canvas.drawLine(x2, y2, endX, endY, mPaint);
         */

        int left = width / 2 - mArrowDrawableWidth / 2;
        int right = width / 2 + mArrowDrawableWidth / 2;
        int top = height / 2 - mArrowDrawableHeight / 2;
        int bottom = height / 2 + mArrowDrawableHeight / 2;
        mArrowDrawable.setBounds(left, top, right, bottom);
        mArrowDrawable.draw(canvas);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right,
            int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        width = right - left;
        height = bottom - top;

    }

}
